<!--
  ~ Copyright (c) 2025. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  ~ Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
  ~ Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
  ~ Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
  ~ Vestibulum commodo. Ut rhoncus gravida arcu.
  -->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <title>Nova Error Page</title>
    <style>
        :root {
            --theme: rgba(33, 108, 232, 0.9);
            --theme-70: rgba(79, 164, 217, 0.7);
            --theme-50: rgba(161, 209, 248, 0.59);
            --line-height: 20px;
            --border-radius: 8px;
            --box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        .main-container-1 {
            max-width: 1400px;
            margin: 0 auto;
            padding: 20px;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background-color: #f8f9fa;
            margin: 0;
            padding: 20px;
            line-height: 1.5;
        }

        h2 {
            color: var(--theme);
        }

        .error-container {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 20px !important;
            background: linear-gradient(to right, #fff, #f8f9fa);
            border-left: 4px solid var(--theme);
            width: 100%;
            box-sizing: border-box;
            overflow: hidden;
        }

        .error-details {
            display: flex;
            flex-direction: column;
        }

        .error-title {
            font-size: 24px;
            font-weight: 600;
            color: #2d3748;
            margin: 0 0 8px;
        }

        .error-message {
            font-size: 18px;
            color: var(--theme);
            margin-top: 8px;
        }

        .version-details {
            text-align: right;
            color: #888;
        }

        .main-container {
            display: grid;
            grid-template-columns: 250px minmax(0, 1fr);
            gap: 20px;
            margin-top: 20px;
            width: 100%;
            box-sizing: border-box;
        }

        .file-list {
            list-style: none;
            margin: 0;
            background: #f8f9fa;
            border-radius: var(--border-radius);
            padding: 10px 0;
            width: 100%;
            overflow-x: hidden;
            word-break: break-word;
        }

        .file-list li {
            padding: 12px 15px;
            margin: 2px 0;
            border-radius: 4px;
            cursor: pointer;
            transition: all 0.2s ease;
            font-size: 15px;
            word-wrap: break-word;
            width: 100%;
            box-sizing: border-box;
        }

        .file-list li:hover {
            background-color: #edf2f7;
        }

        .file-list li.active {
            background-color: var(--theme);
            color: #fff;
            box-shadow: 0 2px 4px rgba(33, 108, 232, 0.2);
        }

        .file-list li.active .number {
            color: #e5dddd;
        }

        .code-container {
            flex-grow: 1;
            overflow: hidden;
            width: 100%;
            box-sizing: border-box;
        }

        .container {
            background-color: #fff;
            border-radius: var(--border-radius);
            box-shadow: var(--box-shadow);
            padding: 15px;
            margin-bottom: var(--line-height);
            transition: all 0.3s ease;
        }

        .code-container pre {
            padding: 0;
            overflow-x: auto;
            position: relative;
            display: inherit;
            margin: 0;
        }

        #code {
            position: relative;
            z-index: 2;
            overflow: auto;

            width: 100%;
        }

        #current {
            background: var(--theme-50);
            display: block;
        }

        #current .ln-num {
            padding: 5px 8px;
            background: var(--theme-70);
        }

        #current .ln-num:before {
            color: white;
        }

        .code {
            font-family: 'Fira Code', 'Consolas', monospace;
            font-size: 14px;
            line-height: 1.6;
        }

        .number {
            font-size: 13px;
            color: gray;
            margin-left: 5px;
        }

        .request-container {
            background-color: #fff;
            padding: 25px;
            border-radius: var(--border-radius);
            box-shadow: var(--box-shadow);
        }

        .section {
            margin-bottom: 20px;
        }

        .section h2 {
            margin-bottom: 10px;
        }

        .url, .headers, .body {
            padding: 10px;
            border-radius: 5px;
        }

        .headers table {
            width: 100%;
            border-collapse: collapse;
            border-radius: var(--border-radius);
            overflow: hidden;
        }

        .headers th, .headers td {
            text-align: left;
            padding: 12px 15px;
            border-bottom: 1px solid #e2e8f0;
        }

        .headers th {
            background-color: #f1f5f9;
            font-weight: 600;
        }

        .headers tr:nth-child(even) {
            background-color: #f9f9f9;
        }

        .headers tr:hover {
            background-color: #e1e1e1;
        }

        .code-block {
            background-color: #1a202c;
            color: #e2e8f0;
            padding: 15px;
            border-radius: var(--border-radius);
            font-family: 'Fira Code', 'Consolas', monospace;
            width: 100%;
            overflow-x: auto;
            white-space: pre-wrap;
            word-break: break-word;
        }

        .request-method {
            background: var(--theme);
            color: #fff;
            padding: 6px 12px;
            border-radius: 20px;
            font-size: 14px;
            font-weight: 500;
        }

        .request-title {
            margin-bottom: 15px;
        }

        .ln-num::before {
            color: #777;
            font-style: normal;
            font-weight: normal;
            content: attr(data-num);
        }

        .ln-num {
            -webkit-touch-callout: none;
            -webkit-user-select: none;
            -khtml-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
            position: sticky;
            z-index: 2;
            left: 0;
            width: 2.4em;
            height: 100%;
            text-align: center;
            display: inline-block;
            background: #f1f5f9;
            border-right: 1px solid #e2e8f0;
        }

        .param-item {
            margin: 5px 0;
            font-size: 14px;
            word-wrap: break-word;
        }

        .highlight-function {
            color: #0000BB;
        }

        .highlight-class {
            color: var(--theme);
        }

        .highlight-type {
            color: #007700;
        }

        .highlight-args {
            font-style: italic;
            font-weight: lighter;
        }

        .highlight-args1 {
            color: #878787;
        }

        .highlight-args2 {
            color: #939393;
        }

        .key {
            width: 200px
        }

        .value {
            word-wrap: break-word;
            word-break: break-all;
        }

        .sidebar {
            position: sticky;
            top: 20px;
            height: fit-content;
            width: 100%;
            box-sizing: border-box;
        }

        .file-list-container {
            padding: 0;
        }

        .file-list-header {
            padding: 15px;
            font-weight: 600;
            border-bottom: 1px solid #e2e8f0;
        }

        .content-area {
            display: flex;
            flex-direction: column;
            gap: 20px;
            min-width: 0;
            width: 100%;
            box-sizing: border-box;
        }

        .code-section {
            padding: 0;
        }

        .code-header {
            padding: 15px;
            border-bottom: 1px solid #e2e8f0;
        }

        .code-content {
            margin: 0;
            padding: 15px;
            overflow-x: auto;
            white-space: pre;
            word-wrap: normal;
        }

        .section-group {
            display: grid;
            gap: 20px;
            margin-bottom: 20px;
            width: 100%;
        }

        .request-section {
            padding: 20px;
            width: 100%;
            overflow-x: hidden;
        }

        .request-info {
            background-color: #f8f9fa;
            border-radius: var(--border-radius);
            padding: 15px;
        }

        .request-url {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 15px;
        }

        .table-wrapper {
            width: 100%;
            overflow-x: auto;
            box-sizing: border-box;
        }

        .info-table {
            width: 100%;
            min-width: 600px;
            border-collapse: collapse;
        }

        .info-table th,
        .info-table td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #e2e8f0;
        }

        .info-table th {
            background-color: #f1f5f9;
            font-weight: 600;
        }

        .error-file {
            color: #666;
            font-size: 14px;
            margin-top: 8px;
        }

        .version-item {
            margin-bottom: 5px;
        }

        @media (max-width: 1024px) {
            .main-container {
                grid-template-columns: 1fr;
            }

            .sidebar {
                position: static;
                width: 100%;
            }

            .main-container-1 {
                padding: 10px;
            }
        }

        *, *:before, *:after {
            box-sizing: border-box;
        }

        /* 代码行样式优化 */
        .code-line {
            display: flex;
            align-items: center;
            line-height: 1.5;
            font-size: 13px;
            white-space: pre;
        }

        /* 行号样式优化 */
        .ln-num {
            display: inline-flex;
            align-items: center;
            padding: 0 8px;
            min-width: 40px;
            background: #f1f5f9;
            border-right: 1px solid #e2e8f0;
            color: #64748b;
            user-select: none;
            font-family: monospace;
        }

        /* 代码内容样式 */
        .code-content {
            display: inline-flex;
            padding: 0;
            font-family: 'Fira Code', Consolas, Monaco, 'Courier New', monospace;
            overflow-x: auto;
            width: 100%;
        }

        /* 当前行高亮 */


        #current .ln-num {
            font-weight: bold;
        }

        /* 代码容器样式 */
        .code-section {
            background: #ffffff;
            border: 1px solid #e2e8f0;
            border-radius: var(--border-radius);
            overflow: hidden;
        }

        /* 确保pre标签不会破坏布局 */
        pre {
            margin: 0;
            padding: 0;
            display: inline;
        }

        /* 代码块整体容器 */
        .code-block {
            font-size: 13px;
            line-height: 1.5;
            overflow-x: auto;
        }
    </style>
</head>
<body>

<div class="main-container-1">
    <div class="container error-container">
        <div class="error-details">
            <h1 class="error-title">{ERROR_TYPE}</h1>
            <div class="error-message">{ERROR_MESSAGE}</div>
        </div>
        <div class="version-details">
            <div class="version-item">PHP {PHP_VERSION}</div>
            <div class="version-item">Nova {NOVA_VERSION}</div>
        </div>
    </div>
    <div class="main-container">
        <div class="sidebar">
            <div class="container file-list-container">
                <div class="file-list-header">Stack Trace</div>
                <ul class="file-list">
                    {TEMPLATE_LIST}
                </ul>
            </div>
        </div>

        <div class="content-area">
            <div class="container code-section">
                <div class="code-header" id="header"></div>
                <pre class="code-content">
                    <code id="code"></code>
                </pre>
            </div>

            <div class="container request-section">
                <div class="section-group">
                    <div class="section request-info">
                        <h2>Request Information</h2>
                        <div class="request-url">
                            <span class="request-method">{REQUEST_METHOD}</span>
                            <span class="request-uri">{REQUEST_URI}</span>
                        </div>
                        <div class="code-block">{REQUEST_INFO}</div>
                    </div>

                    <div class="section">
                        <h2>Headers</h2>
                        <div class="table-wrapper">
                            <table class="info-table">
                                <thead>
                                <tr>
                                    <th class="key">Header</th>
                                    <th class="value">Value</th>
                                </tr>
                                </thead>
                                <tbody>
                                {REQUEST_HEADERS}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>

                <div class="section-group">
                    <div class="section">
                        <h2>Request Body</h2>
                        <div class="code-block">{REQUEST_BODY}</div>
                    </div>

                    <div class="section">
                        <h2>Routing Information</h2>
                        <div class="table-wrapper">
                            <table class="info-table">
                                <thead>
                                <tr>
                                    <th class="key">Parameter</th>
                                    <th class="value">Value</th>
                                </tr>
                                </thead>
                                <tbody>
                                {REQUEST_ROUTING}
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <div class="section">
                        <h2>Server Variables</h2>
                        <div class="table-wrapper">
                            <table class="info-table">
                                <thead>
                                <tr>
                                    <th class="key">Variable</th>
                                    <th class="value">Value</th>
                                </tr>
                                </thead>
                                <tbody>
                                {REQUEST_SERVER}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<div id="templates" style="display: none;">
    {TEMPLATE_CONTENTS}
</div>


<script>
    function showCode(fileKey) {
        try {
            const codeElement = document.getElementById('code');
            const headerElement = document.getElementById('header');

            // 获取模板内容
            const headerTpl = document.getElementById(`header${fileKey}`);
            const template = document.getElementById(`file${fileKey}`);

            // 详细的错误检查
            if (!headerTpl) {
                console.error(`Header template not found for key: ${fileKey}`);
                return;
            }
            if (!template) {
                console.error(`File template not found for key: ${fileKey}`);
                return;
            }
            if (!codeElement) {
                console.error('Code element not found');
                return;
            }
            if (!headerElement) {
                console.error('Header element not found');
                return;
            }

            // 更新活动状态
            document.querySelectorAll('.file-list li').forEach(li => {
                li.classList.remove('active');
                if (li.getAttribute('data-file-key') === fileKey) {
                    li.classList.add('active');
                }
            });

            // 更新内容
            try {
                headerElement.innerHTML = headerTpl.innerHTML || '';
                codeElement.innerHTML = template.innerHTML || '';
            } catch (e) {
                console.error('Error updating content:', e);
                return;
            }

            // 调整宽度
            setTimeout(() => {
                const currentElement = document.getElementById('current');
                if (currentElement && codeElement) {
                    const scrollWidth = codeElement.offsetWidth;
                    currentElement.style.width = `${scrollWidth}px`;
                }
            }, 0);
        } catch (error) {
            console.error('Error in showCode:', error);
        }
    }

    // 初始化函数
    function initializeErrorPage() {
        try {
            // 检查必要的元素是否存在
            const templates = document.getElementById('templates');
            if (!templates) {
                console.error('Templates container not found');
                return;
            }

            // 获取第一个文件并显示
            const firstFile = document.querySelector('.file-list li');
            if (firstFile) {
                const fileKey = firstFile.getAttribute('data-file-key') || '0';
                showCode(fileKey);
            } else {
                console.error('No files found in the list');
            }
        } catch (error) {
            console.error('Error during initialization:', error);
        }
    }

    // 等待DOM加载完成
    document.addEventListener('DOMContentLoaded', initializeErrorPage);

    // 优化的resize事件处理
    let resizeTimeout;
    window.addEventListener('resize', function () {
        clearTimeout(resizeTimeout);
        resizeTimeout = setTimeout(() => {
            const codeElement = document.getElementById('code');
            const currentElement = document.getElementById('current');
            if (codeElement && currentElement) {
                currentElement.style.width = `${codeElement.offsetWidth}px`;
            }
        }, 100);
    });
</script>
</body>
</html>
